<?php
// +----------------------------------------------------------------------
// | title: 标题注释
// +----------------------------------------------------------------------
// | Author: TZ.Leong
// +----------------------------------------------------------------------
// | Date: 2020/2/18 15:12
// +----------------------------------------------------------------------

namespace app\single\model;


use think\exception\DbException;
use think\Model;

class TableMaxIdModel extends Model
{
    protected $table = "l_table_max_id";

    public function getMaxId($tableName, $field = "value")
    {
        return $this->where("table_name", $tableName)->value($field);
    }

    public function updateMaxId($tableName, $value)
    {
        $res = $this->where("table_name", $tableName)->update(["value" => $value]);
        if($res === 0){
            try{
                $res = $this->insert([
                    "table_name" => $tableName,
                    "value" => $value
                ]);
            }catch(DbException $e){
                $res = true;
            }
        }
        return $res;
    }
}